import service from '../utils/request';

const common = {
    list(mod, pageSize, page, isPagi) {
        return service.get(mod, {params: {per_page: pageSize, page: page, pagi: isPagi}})
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    },
    add(mod, data) {
        return service.post(mod, data)
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    },
    edit(mod, data) {
        return service.put(mod, data)
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    },
    delete(mod, id) {
        return service.delete(mod + '/' + id)
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    },
    search(mod, pageSize, page, data) {
        return service.post(mod + '/search' + '?per_page=' + pageSize + '&page=' + page, data)
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    },
    get(mod, id) {
        return service.get(mod + '/' + id)
            .then(data => {
                return Promise.resolve(data)
            })
            .catch(err => {
                return Promise.reject(err)
            })
    }
}

export default common;